package com.eascs.p2p.investor.server.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.p2p.common.entity.InvestorBankEntity;
import com.eascs.p2p.common.entity.InvestorEntity;
import com.eascs.p2p.common.vo.ModelResult;
import com.eascs.p2p.investor.dao.InvestorBankDao;
import com.eascs.p2p.investor.dao.InvestorDao;
import com.eascs.p2p.investor.server.InvestorBankServiceInner;

@Service
public class InvestorBankServiceInnerImpl implements InvestorBankServiceInner {
	private static Logger logger = LoggerFactory.getLogger(InvestorBankServiceInnerImpl.class);

	@Autowired
	private InvestorBankDao investorBankDao;
	@Autowired
	private InvestorDao investorDao;

	@Override
	@Transactional(transactionManager = "transactionManager")
	public ModelResult<Boolean> investorBindBank(InvestorEntity investor, InvestorBankEntity investorBank) {
		ModelResult<Boolean> result = new ModelResult<>();
		if (investor == null || investorBank == null) {
			logger.error("绑卡信息修改失败，参数为空, investor:{}, investorBank:{}", investor, investorBank);
			return result.withError("InvestorBankServiceInner.investorBindBank", "绑卡信息修改失败，参数为空");
		}
		boolean investorResult = investorDao.updateInvestor(investor);
		if (!investorResult) {
			throw new RuntimeException("绑卡信息修改失败");
		}
		int bankResult = investorBankDao.insertInvestorBank(investorBank);
		if (bankResult <= 0) {
			throw new RuntimeException("绑卡信息修改失败");
		}
		result.setModel(true);
		return result;
	}

}
